#include<reg51.h>

//定义字型码数组：编码依次表示0~5
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d};

void display()
{
	unsigned char i;
	for(i=0;i<6;i++)
	{
		P1 = dispcode[i]; 	//从字型码数组里依次取0~5
		P2 = P2<<1;					//公共端P2左移1位
		P1 = 0x00;					//熄灭数码管去重影
		if(P2 == 0x40)			//当左移到P2.6口时
			P2 = 0x01;				//重置回到P2.0口
	}
}

void main()
{
	P2 = 0x01; //公共端P2赋初始值
	while(1)
	{
		 display();
	}
}